package com.qfedu.mavenk.beanDemo3;

import com.qfedu.mavenk.beanDemo2.App06;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc: 测试注解装配
 * @datatime: 2022/10/20 11:27
 */
@Service
//@Service 业务层class的注册bean
//@Component dao层class注册bean
@Scope("prototype")
//@Scope("singleton"),singleton单例模式，prototype多例模式
public class App07 {
    //字段注入（推荐）
    @Autowired  //依赖注入
    @Qualifier("mail")      //选择注册的bean精确注入
    private Service mainService;
    @Autowired  //byType/byName
    private Main main;

    //构造注入

    //set注入

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        App07 app07 = (App07) context.getBean("app07");
        System.out.println(app07);
        App07 app08 = (App07) context.getBean("app07");
        System.out.println(app08);

        System.out.println(app07.mainService);
        System.out.println(app07.main);
    }
}
